<template>
	<view class="myOrder">
		<view class="tabs">
			<block v-for="item in tabs" :key="item.val">
				<view class="type_item" @tap="clickType(item.val)">
					<view class="type_name" :class="{'active_name':item.val==data.type}">{{item.name}}</view>
					<view class="under_line" :class="{'active_line':item.val==data.type}"></view>
				</view>
			</block>
		</view>
		<view class="order_list">
			<block v-for="(v,i) in list" :key="i">
				<view class="order_item">
					<view class="order_info" @click="toDetail(v)">
						<view style="position: relative;">
							<image :src="v.productInfo.image" mode="aspectFill" class="cover_img"></image>
							<view class="order_name">{{ v.actName }}</view>
						</view>
						
						<view class="">
							<view class="title">{{ v.productInfo.storeName }}</view>
							<view class="time">时间：{{ v.productInfo.activityStartTime }}</view>
							<view class="other_info">
								<view class="tags">
									<view class="">{{ v.productInfo.topic }}</view>
								</view>
								<view class="price">
									<text>￥</text>
									<text class="pirce_val">{{ v.payPrice }}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="order_btns">
						<view class="btn_item" v-if="!v.paid" @click="toPay(v)">去付款</view>
						<view class="btn_item dark_btn" v-if="v.paid && v.status==1 && v.refundStatus === 1" @click="toDetail(v)">退款中</view>
						<view class="btn_item dark_btn" v-if="v.paid && v.refundStatus === 2" @click="toDetail(v)">退款完成</view>
						<view class="btn_item dark_btn" v-if="v.paid && v.status==1 && v.refundStatus === 0" @click="toDetail(v)">待出行</view>
						<button class="btn_item" v-if="v.paid && v.status == 2&& !v.isReply"  @tap="$to(`/pages/mine/evaluate/evaluate?id=${v.id}`)">评价</button>
						<button class="btn_item dark_btn" v-if="v.paid && v.status == 2&& v.isReply">已评价</button>
					</view>
				</view>
			</block>
			<view style="text-align: center;margin-top: 100rpx;" v-if="list.length==0">
				<image style="width: 200rpx;height: 200rpx;" src="/static/nodata.png"></image>
				<view style="color: #999;text-align: center;">暂无数据</view>
			</view>
			<view style="text-align: center;color: #999;font-size: 24rpx;" v-if="noMoreData&&list.length!=0">
				没有更多啦
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabs: [
					{
						name: '全部',
						val: 0
					}, {
						name: '待出行',
						val: 1
					}, {
						name: '已出行',
						val: 2
					}, {
						name: '售后',
						val: -3
					},
				],
				currentType: 0,
				data: {
					search: '',
					limit: 10,
					page: 1,
					type: 0
				},
				totalPage: 1,
				noMoreData: false,
				list: [],
			};
		},
		methods: {
			clickType(type) {
				this.data.type = type;
				this.data.page = 1;
				this.getOrder();
			},
			linkTo(url) {
				uni.navigateTo({ url });
			},
			async getOrder() {
				const res = await this.$api.get('order/list',this.data);
				if(res.code == 200) {
					var arr = [],totalPage = 1;
					if( res.data !== 'null' && res.data !== null) {
						totalPage = res.data.totalPage;
						arr = res.data.list || [];
						arr.forEach(v => {
							v.isOpen = false;
							v.actName = this.activityName(v.productInfo.activity)
						})
					}
					if (this.data.page == 1) {
						this.list = arr || [];
						this.totalPage = totalPage || 1;
					} else {
						this.list.push(...arr);
					}
					this.data.page != 1 && this.list.length == 0 ? this.noMoreData = true : this.noMoreData = false
				}
			},
			activityName(v) {
				switch (parseInt(v)){
					case 1:
						return '党建'
						break;
					case 2:
						return '团建'
						break;
					case 3:
						return '研学产品'
						break;
					case 4:
						return '冬夏令营'
						break;
					case 5:
						return '红领巾'
						break;
					case 6:
						return '托管'
						break;
					default:
						return '赛事'
						break;
				}
			},
			toDetail(v) {
				uni.navigateTo({
					url: `/pages/mine/orderDetail?orderId=${v.orderId}&id=${v.id}`
				})
			},
			toPay(v) {
				this.$to(`/pages/index/payOrder?orderNo=${v.orderId}&orderId=${v.id}&payPrice=${v.payPrice}`)
			},
			
		},
		onLoad(opt) {
			this.data.type = parseInt(opt.type);
			
		},
		onShow() {
			this.getOrder();
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F7F7F7;
	}

	.myOrder {
		position: relative;

		.tabs {
			width: 100%;
			padding: 36rpx 44rpx 14rpx;
			box-sizing: border-box;
			background-color: #ffffff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 6;

			.type_item {
				display: flex;
				flex-direction: column;
				align-items: center;

				.type_name {
					font-size: 26rpx;
					line-height: 26rpx;
					color: #999999;
					font-weight: 400rpx;
					margin-bottom: 10rpx;
				}

				.active_name {
					color: #4F98F6;
					font-weight: bold;
				}

				.under_line {
					width: 54rpx;
					height: 6rpx;
					border-radius: 3rpx;
				}

				.active_line {
					background-color: #4F98F6;
				}
			}
		}

		.order_list {
			padding: 120rpx 26rpx 30rpx;
			box-sizing: border-box;

			.order_item {
				width: 100%;
				padding: 20rpx 26rpx 26rpx;
				box-sizing: border-box;
				background-color: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;

				.order_info {
					display: flex;
					align-items: flex-start;
					padding-bottom: 14rpx;
					border-bottom: 1rpx dashed #F0F0F0;
					margin-bottom: 26rpx;

					.cover_img {
						width: 200rpx;
						height: 160rpx;
						border-radius: 14rpx;
						margin-right: 16rpx;
						background-color: #F7F7F7;
					}
					.order_name {
						position: absolute;
						font-weight: bold;
						left: 0;
						top: 0;
						background-image: linear-gradient(to right top,#EEC684,#F3DCB2);
						padding: 0 15rpx;
						line-height: 40rpx;
						font-size: 21rpx;
						border-radius: 20rpx 0 20rpx 0;
						color: #1A1A1A;
					}

					>view {
						flex: 1;

						.title {
							width: 420rpx;
							font-size: 30rpx;
							line-height: 30rpx;
							font-weight: bold;
							color: #1A1A1A;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}

						.time {
							font-size: 24rpx;
							line-height: 24rpx;
							color: #999999;
							padding: 14rpx 0 22rpx;
						}

						.other_info {
							display: flex;
							justify-content: space-between;

							.tags {
								display: flex;
								align-items: center;

								>view {
									font-size: 22rpx;
									line-height: 22rpx;
									padding: 8rpx 12rpx;
									color: #FF8F01;
									background-color: #FFF2E2;
								}

								>view:not(:last-child) {
									margin-right: 20rpx;
								}
							}

							.price {
								font-size: 24rpx;
								font-weight: bold;
								color: #FF0404;

								.pirce_val {
									font-size: 34rpx;
									color: #FF0000;
								}
							}
						}
					}
				}

				.order_btns {
					display: flex;
					justify-content: flex-end;

					.btn_item {
						margin: 0;
						padding: 0;
						width: 120rpx;
						height: 46rpx;
						border-radius: 10rpx;
						text-align: center;
						line-height: 46rpx;
						color: #fff;
						font-size: 24rpx;
						background-color: #2E80FE;
						margin-left: 20rpx;
					}

					.dark_btn {
						background-color: #E6E6E6;
						color: #999999;
					}

					.red_btn {
						background-color: #F12323;
					}
				}
			}
		}
	}
</style>